package com.zz.springboot.manager.impl;

import com.zz.springboot.dto.MaxMoneyParamDto;
import com.zz.springboot.exception.BizException;
import com.zz.springboot.manager.MaxMoneyParamManager;
import com.zz.springboot.mapper.MaxMoneyParamMapper;
import com.zz.springboot.resp.enums.RespCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MaxMoneyParamManagerImpl implements MaxMoneyParamManager {

    @Autowired
    private MaxMoneyParamMapper maxMoneyParamMapper;


    @Override
    public MaxMoneyParamDto getMaxMoneyParam(String username) {

        return maxMoneyParamMapper.getMaxMoneyParam(username);
    }

    @Override
    public void insertMaxMoneyParam(MaxMoneyParamDto maxMoneyParam) {
        Integer res = maxMoneyParamMapper.insertMaxMoneyParam(maxMoneyParam);
        if (res == 0) {
            log.error("插入参数失败");
            throw new BizException(RespCodeEnum.SET_PARAM_FAIL);
        }
    }

    @Override
    public void updateMaxMoneyParam(MaxMoneyParamDto maxMoneyParam) {
        Integer res = maxMoneyParamMapper.updateMaxMoneyParam(maxMoneyParam);
        if (res == 0) {
            log.error("更新参数失败");
            throw new BizException(RespCodeEnum.SET_PARAM_FAIL);
        }
    }

    @Override
    public void deleteMaxMoneyParam(String username) {
        Integer res = maxMoneyParamMapper.deleteMaxMoneyParam(username);
        if (res == 0) {
            log.error("删除参数失败");
            throw new BizException(RespCodeEnum.SET_PARAM_FAIL);
        }
    }
}
